
#ifndef SIMPLEFORMAT_H
#define SIMPLEFORMAT_H

#include <BMap>
#include <BRect>
#include <BRange>
#include <BFont>
#include <BTextFormat>
#include <BScript>

using namespace BWE;

class ScriptFormat : public BTextFormat
{
public:
	struct Item
	{
		BRect			rect;
		BFontHolder		font;
		BColor			color;
		BRange			range;
	};
	typedef BMap<int, Item>		ItemMap;

public:
	ScriptFormat();
	~ScriptFormat();

	virtual void styled(const BStyle* style) override;
	virtual void changed(const BString& text) override;

	ItemMap& itemMap();
	const ItemMap& itemMap() const;

	virtual const BFont* font(int pos) const;
	virtual const BColor* back(int pos) const;
	virtual const BColor* color(int pos) const;

protected:
	BString::const_iterator nextWord(BString& word, const BString& text, BString::const_iterator& cit);
	bool checkType(const BString& text);
	Syntax checkSyntax(const BString& text);

protected:
	void slotAssetChanged(BObject* object, const BValue& value);

private:
	BMap<int, Item>			_itemMap;
	BHolder<const BScript>	_script;
};

#endif
